package com.video.main_video.manager.handle.userInfo;

import com.video.main_video.api.Api;
import com.video.main_video.common.staticData.StaticData;
import com.video.main_video.dao.entity.User;
import com.video.main_video.dao.response.userInfo.UpdateUserInfoRequest;
import com.video.main_video.dao.response.userInfo.UserInfoResponse;
import com.video.main_video.manager.handle.ApiHandler;
import com.video.main_video.manager.mapper.UserMapper;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

@Api
public class UpdateUserInfoManager implements ApiHandler<UpdateUserInfoRequest, UserInfoResponse> {

    @Autowired
    UserMapper userMapper;

    @Transactional
    @Override
    public UserInfoResponse handler(UpdateUserInfoRequest userInfoRequest) {
        updateUser(userInfoRequest);
        UserInfoResponse res=new UserInfoResponse();
        return res;
    }

    private void updateUser(UpdateUserInfoRequest userInfoRequest){
        User user=new User();

        BeanUtils.copyProperties(userInfoRequest,user);
        user.setPassword(null);
        user.setUserId(null);
        user.setId(StaticData.UserId);

        userMapper.updateById(user);
    }
}
